package com.twu.biblioteca;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: mbokhari
 * Date: 11/07/2013
 * Time: 13:16
 * To change this template use File | Settings | File Templates.
 */
public class LogIn implements MenuInterface {
    private Library library = new Library();
    private LibraryNumberGenerator libraryNumberGenerator;
    private Notifier notifier = new Notifier();

    public LogIn(Library library, LibraryNumberGenerator libNumGen) {
        this.library = library;
        libraryNumberGenerator = libNumGen;
    }

    public void login(long number, String password) {
        String formattedNumber = libraryNumberGenerator.formatLibraryNumber(number);

        for (Member member : library.returnAllMembers()) {
            if (member.getLibraryNumber().equals(formattedNumber)) member.memberLogIn(password);
        }

    }

    @Override
    public void runItems() throws IOException {

        notifier.printMessage("Please enter your library number\n>>");

        InputReader inputReader = new InputReader();
        long libraryNumber = inputReader.readUserInputInt();

        notifier.printMessage("Please enter your password\n>>");
        String password = inputReader.readUserInputString();

        login(libraryNumber, password);
    }
}
